<template>
<div>
  <!--  面包屑导航-->
  <el-breadcrumb separator-class="el-icon-arrow-right">
    <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>订单管理</el-breadcrumb-item>
    <el-breadcrumb-item>订单列表</el-breadcrumb-item>
  </el-breadcrumb>
  <el-card>
    <!--    表单输入框-->
    <el-row :gutter="30">
      <el-col :span="7">
        <div style="margin-top: 15px;">
          <el-input placeholder="请输入内容" v-model="queryInfo.query"  clearable @clear="getOrdersList">
            <el-button slot="append" icon="el-icon-search" @click="getOrdersList"></el-button>
          </el-input>
        </div>
      </el-col>
    </el-row>
<!--    表格数据-->
    <el-table :data="ordersList" border stripe>
      <el-table-column type="index"></el-table-column>
      <el-table-column label="订单编号" prop="order_number"></el-table-column>
      <el-table-column label="订单价格" prop="order_price"></el-table-column>
      <el-table-column label="是否付款">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.pay_status === '1'">已付款</el-tag>
          <el-tag type="danger" v-else>未付款</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="是否发货" prop="is_send"></el-table-column>
      <el-table-column label="下单时间">
        <template slot-scope="scope">
          {{scope.row.create_time|dateFormat}}
        </template>
      </el-table-column>
      <el-table-column label="操作">
<!--          <template slot-scope="scope">-->
            <el-button @click="showEditOrderDialogVisible" size="mini" icon="el-icon-edit" type="primary"></el-button>
            <el-button @click="showLocationOrderDialogVisible" size="mini" icon="el-icon-map-location" type="success"></el-button>
<!--          </template>-->
      </el-table-column>
    </el-table>
<!--    分页-->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="queryInfo.pagenum"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="5"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </el-card>
<!--  修改订单对话框-->
  <el-dialog
    title="修改地址"
    :visible.sync="editOrderDialogVisible"
    width="70%"
    @close="editDialogHandleClose"
  >
    <el-form :model="editForm" :rules="editFormRules" ref="editFormRuleForm" label-width="100px">
      <el-form-item label="省市区/县" prop="address1">
        <el-cascader :options="citydata" v-model="editForm.address1"></el-cascader>
      </el-form-item>
      <el-form-item label="详细地址" prop="address2">
        <el-input v-model="editForm.address2"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
    <el-button @click="editOrderDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="editOrderDialogVisible = false">确 定</el-button>
  </span>
  </el-dialog>
<!--  展示物流进度-->
  <el-dialog
    title="物流进度"
    :visible.sync="locationOrderDialogVisible"
    width="70%"
    @close="showLocationDialogHandleClose"
  >
    <span>asd</span>
  </el-dialog>
</div>
</template>

<script>
import citydata from '@/views/orders/citydata'
export default {
  name: 'orders',
  data () {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 5
      },
      total: 0,
      ordersList: [],
      // 修改对话框bool
      editOrderDialogVisible: false,
      // 展示物流进度
      locationOrderDialogVisible: false,
      // 修改表单数据
      editForm: {
        address1: '',
        address2: ''
      },
      editFormRules: {
        address1: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        address2: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ]
      },
      citydata,
      // 物流信息
      progressInfo: {}
    }
  },
  created () {
    this.getOrdersList()
  },
  methods: {
    async getOrdersList () {
      const { data } = await this.$axios.get('orders', { params: this.queryInfo })
      if (data.meta.status !== 200) return this.$message.error(data.meta.msg)
      this.ordersList = data.data.goods
      this.total = data.data.total
      console.log(data)
    },
    handleSizeChange (newSize) {
      this.queryInfo.pagesize = newSize
      this.getOrdersList()
    },
    handleCurrentChange (newNum) {
      this.queryInfo.pagenum = newNum
      this.getOrdersList()
    },
    // 显示修改对话框
    showEditOrderDialogVisible () {
      this.editOrderDialogVisible = true
    },
    // 关闭修改对话框清空数据
    editDialogHandleClose () {
      this.$refs.editFormRuleForm.resetFields()
    },
    // 展示物流进度
    async showLocationOrderDialogVisible () {
      const { data } = await this.$axios.get('/kuaidi/804909574412544580')
      if (data.meta.status !== 200) return this.$message.error(data.meta.message)
      console.log(data)
      this.progressInfo = data.data
      this.locationOrderDialogVisible = true
    },
    // 关闭物流进度对话框
    showLocationDialogHandleClose () {}
  }
}
</script>

<style scoped>
.el-cascader{
  width: 100%;
}
</style>
